<template>
  <view class="incomeListMain">
    <view class="incomeListBox">
      <view v-if="list.length > 0">
        <view
          class="incomelistItem solid-bottom"
          v-for="(item, index) in list"
          :key="index"
        >
          <view class="top flex align-center justify-between">
            <view v-if="item.mercNm">{{ item.mercNm }}</view>
            <view v-else>激活返现</view>
            <view>
              <text v-if="item.revert_money > 0">+</text>
              {{ item.revert_money }}
            </view>
          </view>
          <view class="sub flex align-center justify-between">
            <view>{{ item.number }}</view>
            <view v-if="item.active_time">{{
              $u.timeFormat(item.active_time, "yyyy-mm-dd hh:MM:ss")
            }}</view>
          </view>
        </view>
      </view>
      <view
        class="noMachine flex align-center"
        v-if="list.length == 0 && isLoad"
      >
        <image
          src="../../static/images/noData/zwjl.png"
          mode="widthFix"
        ></image>
        <text>暂无收益</text>
      </view>
    </view>
    <u-loadmore
      :status="status"
      @loadmore="loadmore"
      v-if="list.length > 0"
      style="padding: 40rpx 0"
    />
    <toast></toast>
    <u-back-top :scroll-top="scrollTop"></u-back-top>
  </view>
</template>

<script>
export default {
  data() {
    return {
      scrollTop: 0,
      page: 1,
      limit: 15,
      list: [],
      status: "loadmore",
      noMore: false,
      isLoad: false,
	  searchDate:'',
    };
  },
  onLoad(options) {
	this.searchDate = options.yearDate
    this.incomeList();
  },
  onPageScroll(e) {
    this.scrollTop = e.scrollTop;
  },
  onPullDownRefresh() {
    this.page = 1;
    this.list = [];
    this.status = "loadmore";
    this.noMore = false;
    this.isLoad = false;
    this.incomeList();
  },
  onReachBottom() {
    if (this.noMore) {
      this.status = "nomore";
    } else {
      this.status = "loading";
      this.page = ++this.page;
      this.incomeList();
    }
  },
  // 点击下载更多
  loadmore() {
    if (this.noMore) {
      this.status = "nomore";
    } else {
      this.page = ++this.page;
      this.status = "loadmore";
      this.incomeList();
    }
  },
  methods: {
    incomeList() {
      this.$u.api
        .zdfxGetPersonalActiveIncomes({
          page: this.page,
          limit: this.limit,
		  searchMonth:this.searchDate
        })
        .then((res) => {
          if (res.status == 200) {
            let datas = res.result;
            if (this.page == 1 && datas.length == 0) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page == 1 && datas.length < this.limit) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page > 1 && datas.length < this.limit) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page > 1 && datas.length == this.limit) {
              this.status = "loading";
            }
            this.list = this.list.concat(datas);
          } else {
            this.$refs.uToast.show({
              title: res.msg,
              type: "error",
              duration: 1200,
            });
          }
          this.isLoad = true;
          uni.stopPullDownRefresh();
        })
        .catch((res) => {
          if (res.errMsg == "request:fail timeout") {
            this.$u.toast("请求超时，请重试!");
          } else if (res.errMsg == "request:fail") {
            this.$u.toast("请求失败，请重试");
          } else {
             this.$u.toast("请求失败，请重试");
          }
          this.$loading(false);
          setTimeout(() => {
            this.$u.route({
              type: "navigateBack",
              delta: 1,
            });
          }, 2000);
        });
    },
  },
};
</script>

<style lang="scss">
page {
  background: #fff;
}
.incomeListMain {
  padding: 0 30rpx;
  .incomelistItem {
    padding: 26rpx;
	box-shadow: 0rpx 0rpx 8rpx #ccc;
	border-radius: 14rpx;
	margin-top: 20rpx;
    .top {
      view {
        &:first-of-type{
          font-size:32rpx;
          font-weight:bold;
        }
        &:last-of-type {
          font-size: 50rpx;
          color: #fb4535;
          font-family: "numberFont";
          text {
            position: relative;
            top: -4rpx;
          }
        }
      }
    }
    .sub {
      view {
        &:first-of-type {
          font-size:26rpx;
        }
        &:last-of-type {
          color: #999;
		  font-family: numberFont;
        }
      }
    }
  }
}
</style>
